package com.huike.web.controller.system;

import com.huike.clues.domain.SysDictData;
import com.huike.clues.service.ISysDictDataService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController {

    @Autowired
    private ISysDictDataService sysDictDataService;

    @GetMapping("/type/{dictType}")
    public AjaxResult getDictDataByType(@PathVariable String dictType) {

        return AjaxResult.success(sysDictDataService.getDictDataByType(dictType));
    }


    @GetMapping("/list")
    public TableDataInfo<List<SysDictData>> list(SysDictData sysDictData) {
        startPage();
        List<SysDictData> list = sysDictDataService.list(sysDictData);
        return  getDataTable(list);
    }


    @PostMapping
    public AjaxResult add(@Valid @RequestBody SysDictData sysDictData) {
        sysDictDataService.add(sysDictData);
        return AjaxResult.success();
    }


    @GetMapping("/{dictCode}")
    public AjaxResult getDetailsById(@PathVariable Long dictCode) {
        return AjaxResult.success(sysDictDataService.getDetailsById(dictCode));
    }


    @PutMapping
    public AjaxResult update(@Valid @RequestBody SysDictData sysDictData) {
        sysDictDataService.update(sysDictData);
        return AjaxResult.success();
    }

    @DeleteMapping("/{dictCodes}")
    public AjaxResult delete(@PathVariable Long[] dictCodes) {
        sysDictDataService.deleteByIds(dictCodes);
        return AjaxResult.success();
    }


}
